#pragma once

#include "GkDevice.h"

namespace gk
{
	class DeviceCommon : public Device
	{
	protected:

		void				InitialisePlatform(InitParamsHandle hInitParams);
		void				InitialiseCommon(InitParamsHandle hInitParams);

		void				ShutdownPlatform();
		void				ShutdownCommon();

		// Accessors
		RenderSurfaceHandle	GetBackBuffer();
		ContextHandle		GetSystemContext();
		InitParamsHandle	GetInitParams();



		bool				Present();

	protected:

		// GPU program format
		struct ShaderHeader
		{
			cr::uint32_t	m_fourcc;
			cr::uint32_t	m_numPrograms;
			cr::uint32_t	m_numConstantTables;
		};

		struct ProgramHeader
		{
			cr::uint32_t	m_programType;
			cr::uint32_t	m_codeSize;
		};

		struct ConstantHeader
		{
			cr::uint32_t	m_constantName;
			cr::uint32_t	m_constantType;
			cr::uint32_t	m_offset;
			cr::uint32_t	m_size;
		};

		struct ConstantTableHeader
		{
			cr::uint32_t	m_programType;
			cr::uint32_t	numConstants;
		};

		pf::DisplayConfigHandle		GetDisplayConfig() const;

	private:

		// Members
		Context						m_systemContext;
		RenderSurface				m_backBuffer;
		InitParams					m_initParams;
		pf::DisplayConfigHandle		m_hDisplayConfig;
	};

	inline RenderSurfaceHandle DeviceCommon::GetBackBuffer()
	{
		return m_backBuffer;
	}

	inline ContextHandle DeviceCommon::GetSystemContext()
	{
		return m_systemContext;
	}

	inline InitParamsHandle DeviceCommon::GetInitParams()
	{
		return m_initParams;
	}

	inline pf::DisplayConfigHandle DeviceCommon::GetDisplayConfig() const
	{
		return m_hDisplayConfig;
	}
}